package cn.lbf.stuniversity.classroomequipment.controller;

import cn.lbf.stuniversity.classroomequipment.entity.ClassroomEquipment;
import cn.lbf.stuniversity.classroomequipment.form.ClassroomEquipmentAddForm;
import cn.lbf.stuniversity.classroomequipment.form.ClassroomEquipmentDetailForm;
import cn.lbf.stuniversity.classroomequipment.form.ClassroomEquipmentForm;
import cn.lbf.stuniversity.classroomequipment.service.ClassroomEquipmentService;
import cn.lbf.stuniversity.vo.Result;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/classroomEquip")
@CrossOrigin
public class ClassroomEquipmentController {
    @Autowired
    private ClassroomEquipmentService classroomEquipmentService;

    @PostMapping("/addNew")
    public Result<Map<String,Object>> addNew(@Valid @RequestBody ClassroomEquipmentAddForm form){
        form.setCreatorId("admin");
        form.setCreateTime(new Date());
        return classroomEquipmentService.addNew(form);
    }

    @GetMapping("/queryList")
    public Result<Page<ClassroomEquipment>> queryList(@Valid ClassroomEquipmentForm form){
        System.out.println(form);
        return classroomEquipmentService.queryList(form);
    }

    @GetMapping("/del")
    public Result<String> del(String classroomEquipmentId){
        return classroomEquipmentService.del(classroomEquipmentId);
    }

    @PostMapping("/edit")
    public Result<String> edit(@Valid @RequestBody ClassroomEquipmentDetailForm form){
        return classroomEquipmentService.updateByClassId(form);
    }
}
